//
//  MKTChatItem_5_TVCell.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2021/7/13.
//  Copyright © 2021 moon. All rights reserved.
//

#import "MKTChatItem_5_TVCell.h"

@implementation MKTChatItem_5_TVCell
+ (void)load{
    [self registerTableViewCellFor:[MKTChatItem_5 class]];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.leftView = [[MKTChatTextBlockUIView alloc] init];
        self.leftView.flowlayout.constraintParam = MKUIFlowLayoutConstraintParam_V_T_L;
        [self.contentView addSubview:self.leftView];
        MKUILayoutConstraintItemWrapper *w1 = [MKUILayoutConstraintItemWrapper wrapItem:self.leftView sizeThatFitsBlock:^CGSize(MKUILayoutConstraintItemWrapper * _Nonnull wrapper, CGSize size, BOOL resizeItems) {
            size.width *= 0.5;
            MKTChatTextBlockUIView *leftView = wrapper.originItem;
            CGSize s = [leftView sizeThatFits:size];
            s.width = size.width;
            return s;
        }];
        //
        self.rightView = [[MKTChatTextBlockUIView alloc] init];
        self.rightView.flowlayout.constraintParam = MKUIFlowLayoutConstraintParam_V_T_L;
        [self.contentView addSubview:self.rightView];
        //
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[w1,self.rightView] constraintParam:(MKUIFlowLayoutConstraintParam_H_T_L) contentInsets:UIEdgeInsetsMake(2, 10, 2, 10) interitemSpacing:5];
    }
    return self;
}
- (void)customLayoutSubviews{
    [super customLayoutSubviews];
    CGRect bounds = self.contentView.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (CGSize)customSizeThatFits:(CGSize)size{
    return [self.flowlayout sizeThatFits:size resizeItems:YES];
}
- (void)customReloadCellModel{
    [super customReloadCellModel];
    MKTChatItem_LeftRight *modelValue = self.cellModel.modelValue;
    self.leftView.textBlock = modelValue.left;
    [self.leftView reloadData];
    self.rightView.textBlock = modelValue.right;
    [self.rightView reloadData];
}
@end
